//
//  YSForGetpassViewController.m
//  YSZC
//
//  Created by 张斌 on 16/4/11.
//  Copyright © 2016年 YueShiKeJi. All rights reserved.
//

#import "YSForGetpassViewController.h"










#import "YSTextfield.h"

@interface YSForGetpassViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIView *userview;
@property (weak, nonatomic) IBOutlet UIView *phoneview;

@property (weak, nonatomic) IBOutlet UIView *checkview;
@property (weak, nonatomic) IBOutlet UIView *passview1;
@property (weak, nonatomic) IBOutlet UIView *passview2;


@property (weak, nonatomic) IBOutlet UITextField *user_tx
;
@property (weak, nonatomic) IBOutlet UITextField *phone_tx;
@property (weak, nonatomic) IBOutlet UIButton *getcode_btn;

@property (weak, nonatomic) IBOutlet UITextField *checkcode_tx;

@property (weak, nonatomic) IBOutlet UITextField *pass1_tx;
@property (weak, nonatomic) IBOutlet UITextField *pass2_tx;
@property (weak, nonatomic) IBOutlet UIButton *done_btn;

@end

@implementation YSForGetpassViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.pass1_tx.delegate = self;
    self.pass2_tx.delegate = self;
    
    self.pass1_tx.tag =101;
    self.pass2_tx.tag = 102;
//    UIScrollView* view =(UIScrollView*)self.view;
//    view.contentSize = CGSizeMake(0, 1000);
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.view endEditing:YES];
}

- (void)viewDidLayoutSubviews{
    
    [super viewDidLayoutSubviews];
    
    NSArray* views = @[self.userview,self.phoneview,self.checkview,self.passview1,self.passview2,self.done_btn,self.getcode_btn];
    
    [self settoyuanWithview:views];
}

// 设置圆角的方法
- (void)settoyuanWithview:(NSArray*)views {
    for (UIView* view in views) {
        view.layer.cornerRadius = 5 ;
        view.layer.masksToBounds = YES;

    }
    }
- (IBAction)donebtnclick:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)returnbtn:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}



// 跟随键盘
-(void)changeViewFrame:(NSNotification *)noti{
    //1.获取 结束时候的Frame即可
    //    NSLog(@"%@",noti);
    //2.获取结束的Frame
    CGRect endRect =  [noti.userInfo[@"UIKeyboardFrameEndUserInfoKey"]CGRectValue];
    //拿 结束的Frame中的y值 跟界面的高度做减法 得到 最终 控制器的View 的y值
    CGFloat endY = endRect.origin.y-self.view.frame.size.height+120;
    
    //设置给控制器的View的Frame即可
    CGRect oldFrame=self.view.frame;
    if (endY>0) {
        endY = 0;
    }
    oldFrame.origin.y=endY;
    
    
    self.view.frame=oldFrame;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    if ([textField isKindOfClass:[YSTextfield class]]) {
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeViewFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
        
    }else{
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
    }
   
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
     [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
}

- (void)dealloc
{
     [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
    
}

@end
